import Layout from '@/components/common/Home'
import ParentView from '@/components/layout/ParentView/index.vue'

const setRouter = newRouter => {
	return setFun(newRouter);
}

const setFun = arr => {
    return arr.map(item => {
        let newComponent = undefined
        if (item.component) {
            // Layout ParentView 组件特殊处理
            if (item.component === 'Layout') {
                newComponent = Layout
            } else if (item.component === 'ParentView') {
                newComponent = ParentView
            } else {
                newComponent = () => import(`@/components/page/${item.component}`)
            }
        }
        let cell = {
            path: item.path,
            component: newComponent,
            meta: item.meta
        }
        if (item.children && item.children.length > 0) {
            cell.children = setFun(item.children)
        }
        return cell;
    });
}

export default setRouter;